package com.fsh.anime.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fsh.anime.mapper.DictionaryMapper;
import com.fsh.anime.model.pojos.Dictionary;
import com.fsh.anime.model.vos.Result;
import com.fsh.anime.service.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, Dictionary> implements DictionaryService {

    @Autowired
    private DictionaryMapper dictionaryMapper;
    /**
     * 得到字典
     *
     * @return {@link Result}
     */
    @Override
    public Result getDictionary() {
        //TODO redis缓存

        LambdaQueryWrapper<Dictionary> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.orderByDesc(Dictionary::getLabel);
        List<Dictionary> dictionaryList = dictionaryMapper.selectList(lambdaQueryWrapper);
        return Result.success(dictionaryList);
    }

    /**
     * @param type
     * @return {@link Result}
     * 获取 字典分类 。 根据传递的参数查询
     */
    @Override
    public Result getTypeList(Integer type) {
        LambdaQueryWrapper<Dictionary> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Dictionary::getType,type);
        List<Dictionary> list = dictionaryMapper.selectList(lambdaQueryWrapper);
        return Result.success(list);
    }
}
